/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.DAO;

import java.util.Date;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.Entity.Complaint;

/**
 *
 * @author KIS
 */
@Stateless
public class ComplaintFacade extends AbstractFacade<Complaint> {
    @PersistenceContext(unitName = "ManTechHelpdesk-EjbPU")
    private EntityManager em;
    private Query query;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ComplaintFacade() {
        super(Complaint.class);
    }
    
    @SuppressWarnings("unchecked")
	public List<Complaint> getComplaintListByStatus(int status){
    	query = getEntityManager().createNamedQuery("Complaint.findByStatus");
    	query.setParameter("status", status);
    	return (List<Complaint>) query.getResultList();
    }
    
    @SuppressWarnings("unchecked")
	public List<Complaint> getComplaintListByDateRange(Date fromLodgingDate, Date toLodgingDate){
    	query = getEntityManager().createNamedQuery("Complaint.findByDateRange");
    	query.setParameter("fromLodgingDate", fromLodgingDate);
    	query.setParameter("toLodgingDate", toLodgingDate);
    	return (List<Complaint>)query.getResultList();
    }
    
    @SuppressWarnings("unchecked")
	public List<Complaint> getEmployeesComplaintList(int employeeID, int status){
    	Query query = getEntityManager().createNamedQuery("Complaint.findByEmployeeIDAndStatus");
    	query.setParameter("lodgingEmployeeID", employeeID);
    	query.setParameter("status", status);
    	return (List<Complaint>)query.getResultList();
    }
    
    @SuppressWarnings("unchecked")
	public List<Complaint> getTechniciansComplaintList(int technicianID, int status){
    	Query query = getEntityManager().createNamedQuery("Complaint.findByEmployeeIDAndStatus");
    	query.setParameter("solvingTechnicianID", technicianID);
    	query.setParameter("status", status);
    	return (List<Complaint>)query.getResultList();
    }
    
}
